#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/ui.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <vector>
#include <string>
#include <error.cpp>
using namespace std;

void get_engine_names(vector<string>& engines)
{
    ENGINE_load_builtin_engines();
    auto eng = ENGINE_get_first();

    while(true)
    {
        if (eng == nullptr)
        {
            break;
        }

        engines.push_back(ENGINE_get_id(eng));
        eng = ENGINE_get_next(eng);
    }

    ENGINE_free(eng);
}

void free_engine(ENGINE* eng)
{
    ENGINE_finish(eng);
}

ENGINE* new_engine_by_name(const char* name)
{
    auto  eng = ENGINE_by_id(name);
    if(eng == nullptr)
    {
        throw get_errors();
    }

      if( 1 != ENGINE_init(eng))
    {
        throw get_errors();
    }
    return eng;
}

void get_commands(vector<string>& commands)
{
    commands.push_back("SO_PATH");
}

void run_command(ENGINE* eng, const char* name , const char* arg)
{
    if (1 != ENGINE_ctrl_cmd_string(eng, name, arg, 0)) 
    {
		throw get_errors();
	}
}

